<template>
  <div class="page">
    <div class="main">
      <el-card class="box-card" style="height:800px">
        <div slot="header" class="clearfix">
          <span>
            <navigation />
          </span>
        </div>
        <!-- <div class="list" id="taskScore"> -->
        <b
          style="margin-left:10px;font-size:14px;position: relative;top: -10px;"
        >{{ $route.query.name }}</b>
        <el-scrollbar class="page-component__scroll" style="height:100%">
          <div style="height:630px;">
            <el-table
              :header-cell-style="{ background: '#f5f5f5' }"
              :data="tableData"
              style="width: 100%"
              border
              height="620px"
              row-key="id"
              :tree-props="{ children: 'subtasks', hasChildren: 'hasChildren' }"
            >
              <el-table-column type="index" label="序号" align="center"></el-table-column>
              <el-table-column prop="targetName" label="目标任务名称"></el-table-column>
              <el-table-column label="牵头部门" prop="departmentName"></el-table-column>
              <el-table-column label="一季度任务量">
                <template slot-scope="scope">{{ embellishDate(scope.row.oneQuarterNumber) }}</template>
              </el-table-column>
              <el-table-column label="二季度任务量">
                <template slot-scope="scope">{{ embellishDate(scope.row.twoQuarterNumber) }}</template>
              </el-table-column>
              <el-table-column label="三季度任务量">
                <template slot-scope="scope">{{ embellishDate(scope.row.threeQuarterNumber) }}</template>
              </el-table-column>
              <el-table-column label="全年任务量">
                <template slot-scope="scope">{{ embellishDate(scope.row.allNumber) }}</template>
              </el-table-column>
              <el-table-column fixed="right" width="300" label="操作">
                <template slot-scope="scope">
                  <el-button
                    type="text"
                    v-if="!scope.row.subtasks || scope.row.subtasks.length == 0"
                    @click="setCheck(scope.row)"
                  >查看</el-button>
                </template>
              </el-table-column>
            </el-table>
            <!-- </div> -->
          </div>
        </el-scrollbar>
        <el-pagination
          background
          style="float:right"
          layout="prev, pager, next"
          :page-size="pageSize"
          :current-page="pageNum"
          :total="total"
          @current-change="pageChange"
        ></el-pagination>
      </el-card>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      pageNum: 1,
      pageSize: 10,
      dialogVisible: false,
      dialogGrade: false,
      options: [],
      value: "",
      value1: true,
      input: "",
      tableData: [],
      total: 0,
      currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 4,
      textarea: "",
      objCurr: {
        type: true,
        id: "",
        taskId: "",
        year: "",
        time: "",
        score: "",
      },
      quarterList: [1, 2, 3, 4],
      input2: "",
      taskId: "",
      departmentName: "",
    };
  },
  mounted() {
    this.taskId = this.$route.query.taskId;
    this.departmentName = this.$route.query.departmentName;
    this.getListByPage();
  },
  // 计算属性
  computed: {
    a1() {
      if (this.objCurr.type == true) {
        this.quarterList = [1, 2, 3, 4];
      } else {
        this.quarterList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
      }
      return this.quarterList;
    },
  },
  methods: {
    // 分页
    pageChange(page) {
      this.pageNum = page;
      this.getListByPage();
    },
    embellishDate(text) {
      let _text = "-";
      if (text) {
        _text = text;
      }
      return _text;
    },
    // 新增指标
    addTask(text, val) {
      if (val) {
        if (text == "1") {
          console.log("编辑");
          this.$router.push({
            path: "/RecordList",
            query: {
              type: text,
              parentId: val.taskId,
              departmentName: this.$route.query.departmentName,
              number: val.number,
              upsubtasksId: val.id,
            },
          });
          // 列表编辑按钮
        } else {
          // 列表新增按钮
          console.log(val);
          this.$router.push({
            path: "/RecordList",
            query: {
              type: text,
              parentId: this.taskId,
              id: val.id,
              decompose: val.decompose, //是否分解
            },
          });
        }
      } else {
        // 顶部新增按钮
        this.$router.push({
          path: "/RecordList",
          query: {
            type: text,
            parentId: this.taskId,
            departmentName: this.$route.query.departmentName,
            number: this.$route.query.number,
          },
        });
      }
    },
    setCheck(val) {
      this.$router.push({
        path: "/indicatorsListAudit_3",
        query: { parentId: this.taskId, id: val.id, name: val.targetName },
      });
    },
    setGrade(val) {
      console.log(val);
      for (const key in this.objCurr) {
        this.objCurr[key] = "";
      }
      this.objCurr.taskId = val.id;
      this.objCurr.type = true;
      this.dialogGrade = true;
    },
    // 点击列表打分确认按钮
    dataGrade() {
      // let _this = this.objCurr;
      // if (_this.year == "" || _this.time == "" || _this.score == "") {
      //   this.$message.error("请用户填填完输入框");
      //   return;
      // }

      // if (!/(^[1-9]\d*$)/.test(_this.score)) {
      //   this.$message.error("请用户在分数内写入1-100的正整数");
      //   return;
      // }
      // POST /taskScore/add
      this.$axios
        .post(`/taskScore/add`, this.objCurr, 2)
        .then((res) => {
          if (res.code == 200) {
            console.log(res);
            this.$message({
              message: "数据更新成功",
              type: "success",
            });
            this.dialogGrade = false;
            this.getListByPage();
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    getBack() {
      this.$router.go(-1);
    },
    dataTotal(val) {
      this.pageNum = val;
    },
    // 列表查看按钮
    routerPath(val) {
      // this.$router.push({
      //   path: "/unitboyScore",
      //   query: { subtasksId: val.subtasksId }
      // });
    },
    // 编写备注
    dataRemark() {
      this.dialogVisible = true;
    },
    // 获取数据列表
    getListByPage() {
      let _obj = {
        taskId: this.taskId,
      };
      this.$axios
        .post(
          `/distribution/getListByPage/${this.pageNum}/${this.pageSize}`,
          _obj
        )
        .then((res) => {
          if (res.code == 200) {
            this.tableData = res.data.list;
            this.total = res.data.total;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>
<style scoped>
.page {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.main {
  width: 100%;
  height: 100%;
  /* background: #fff; */
}
.subnav {
  float: left;
  width: 100%;
  height: 60px;
  line-height: 60px;
}
.searchLeft {
  float: left;
  width: 400px;
  /* height: 40px; */
}
.searchLeft > button {
  width: 100px;
  height: 40px;
  background: #409eff;
  color: #fff;
  border: 0px;
  font-size: 16px;
  text-align: center;
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  position: relative;
  left: -8px;
  top: 1px;
}
.searchRight {
  float: left;
  width: auto;
}
.searchRight > span {
  display: inline-block;
  width: 80px;
  height: auto;
  font-size: 14px;
  text-align: center;
  margin-left: 20px;
}
.el-scrollbar__wrap {
  overflow-x: hidden;
}
.page-component__scroll {
  height: 100%;
}
.list {
  width: 100%;
  height: 100%;
  /* padding-top: 60px; */
  padding-bottom: 60px;
}
.laypage {
  width: 100%;
  height: 60px;
  position: relative;
  top: -60px;
  text-align: right;
}
</style>
